home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / CIT.v4 / Demo / ListBrowserDemo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  7.5 KB  |  326 lines

  1. #include <CITGroup.h>
  2. #include <CITButton.h>
  3. #include <CITListBrowser.h>
  4. #include <CITLabel.h>
  5.  
  6. #include <proto/listbrowser.h>
  7. #include <clib/alib_protos.h>
  8. #include <stdlib.h>
  9.  
  10. char* col1[] =
  11. {
  12.   "This is a", "test of the", "ListBrowser", "gadget class.",
  13.   "This is like", "a souped-up", "listview", "gadget.  It", "has many",
  14.   "cool new", "features", "though like", "multiple", "columns,",
  15.   "horizontal", "scrolling,", "images in", "nodes,", "columns titles",
  16.   "and much much", "more!",
  17.   "This is a", "test of the", "ListBrowser", "gadget class.",
  18.   "This is like", "a souped-up", "listview", "gadget.  It", "has many",
  19.   "cool new", "features", "though like", "multiple", "columns,",
  20.   "horizontal", "scrolling,", "images in", "nodes,", "columns titles",
  21.   "and much much", "more!",
  22.   "This is a", "test of the", "ListBrowser", "gadget class.",
  23.   "This is like", "a souped-up", "listview", "gadget.  It", "has many",
  24.   "cool new", "features", "though like", "multiple", "columns,",
  25.   "horizontal", "scrolling,", "images in", "nodes,", "columns titles",
  26.   "and much much", "more!", NULL
  27. };
  28.  
  29. LONG col2[] =
  30. {
  31.   1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  32.   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
  33.   27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
  34.   39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
  35.   51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
  36.   63
  37. };
  38.  
  39. struct ColumnInfo ci[] =
  40. {
  41.   { 80, "Col 1", 0 },
  42.   { 60, "Col 2", 0 },
  43.   { 60, "Col 3", 0 },
  44.   { -1, (STRPTR)~0, -1 }
  45. };
  46.  
  47. struct ColumnInfo fancy_ci[] =
  48. {
  49.   { 100, NULL, 0 },
  50.   { -1, (STRPTR)~0, -1 }
  51. };
  52.  
  53. //
  54. // Some fonts for our fancy list.
  55. //
  56. struct TextAttr helvetica24b = { (STRPTR)"helvetica.font", 24, FSF_BOLD, FPF_DISKFONT };
  57. struct TextAttr times18i = { (STRPTR)"times.font", 18, FSF_ITALIC, FPF_DISKFONT };
  58. struct TextAttr times18 = { (STRPTR)"times.font", 18, 0, FPF_DISKFONT };
  59.  
  60. List labelList;
  61. List imageList;
  62.  
  63. CITApp Application;
  64.  
  65. CITWorkbench   DemoScreen;
  66. CITWindow      DemoWindow;
  67. CITVGroup      winGroup;
  68. CITListBrowser lb;
  69. CITButton      quitButton;
  70. CITLabel       im1,im2;
  71.  
  72. //
  73. // Function prototypes.
  74. ///
  75. struct ClassLibrary * OpenClass(STRPTR, ULONG);
  76. void CloseEvent();
  77. void QuitEvent(ULONG ID);
  78. BOOL makeLabelList(struct List*,char**,LONG*);
  79. BOOL makeImageList(struct List*, Image*,Image*);
  80. VOID freeList(struct List*);
  81.  
  82. int main(void)
  83. {
  84.   BOOL Error=FALSE;
  85.  
  86.   // Create the images
  87.   im1.Text("C");
  88.     im1.FGPen(1);
  89.     im1.BGPen(2);
  90.     im1.Font("helvetica.font", 24);
  91.     im1.SoftStyle(FSF_BOLD);
  92.   im1.Text("lass ");
  93.     im1.FGPen(1);
  94.     im1.BGPen(2);
  95.     im1.Font("times.font", 18);
  96.     im1.SoftStyle(FSF_ITALIC);
  97.   im1.Text("A");
  98.     im1.FGPen(1);
  99.     im1.BGPen(2);
  100.     im1.Font("helvetica.font", 24);
  101.     im1.SoftStyle(FSF_BOLD);
  102.   im1.Text("ct");
  103.     im1.FGPen(1);
  104.     im1.BGPen(2);
  105.     im1.Font("times.font", 18);
  106.     im1.SoftStyle(FSF_ITALIC);
  107.  
  108.   im2.Text("by Phantom Development");
  109.     im2.FGPen(2);
  110.     im2.BGPen(0);
  111.     im2.Font("times.font", 18);
  112.  
  113.   makeLabelList(&labelList,col1,col2);
  114.   makeImageList(&imageList,im1.objectPtr(),im2.objectPtr());
  115.  
  116.   DemoScreen.InsObject(DemoWindow,Error);
  117.     DemoWindow.Position(WPOS_CENTERSCREEN);
  118.     DemoWindow.CloseGadget();
  119.     DemoWindow.DragBar();
  120.     DemoWindow.SizeGadget();
  121.     DemoWindow.DepthGadget();
  122.     DemoWindow.IconifyGadget();
  123.     DemoWindow.Activate();
  124.     DemoWindow.Caption("<- Click to continue");
  125.     DemoWindow.CloseEventHandler(CloseEvent);
  126.     DemoWindow.InsObject(winGroup,Error);
  127.       winGroup.SpaceOuter();
  128.       winGroup.InsObject(lb,Error);
  129.         lb.MinWidth(275);
  130.         lb.MinHeight(150);
  131.         lb.Labels(&labelList);
  132.         lb.ColumnInfo(ci);
  133.         lb.ColumnTitles();
  134.         lb.Editable();
  135.       winGroup.InsObject(quitButton,Error);
  136.         quitButton.Text("Quit");
  137.         quitButton.MaxHeight(20);
  138.         quitButton.EventHandler(QuitEvent);
  139.  
  140.   Application.InsObject(DemoScreen,Error);
  141.  
  142.   // Ok?
  143.   if( Error )
  144.     return 10;
  145.  
  146.   Application.Run();
  147.  
  148.   Application.RemObject(DemoScreen);
  149.  
  150.   freeList(&imageList);
  151.   freeList(&labelList);
  152.  
  153.   return 0;
  154. }
  155.  
  156. void QuitEvent(ULONG ID)
  157. {
  158.   Application.Stop();
  159. }
  160.  
  161.  
  162. int repeatCount = 0;
  163.  
  164. void CloseEvent()
  165. {
  166.   repeatCount++;
  167.  
  168.   switch( repeatCount )
  169.   {
  170.     case 1:
  171.       DemoWindow.Caption("Make Visible 10");
  172.       lb.MakeVisible(10);
  173.       lb.EditNode(8);
  174.       lb.EditColumn(1);
  175.       break;
  176.     case 2:
  177.       DemoWindow.Caption("Show Selected Auto-Fit");
  178.       lb.ShowSelected();
  179.       lb.AutoFit();
  180.       lb.HorizontalProp();
  181.       break;
  182.     case 3:
  183.       DemoWindow.Caption("Multi-select, Virtual Width of 500");
  184.       lb.MultiSelect();
  185.       lb.VirtualWidth(500);
  186.       lb.AutoFit(FALSE);
  187.       break;
  188.     case 4:
  189.       DemoWindow.Caption("Detached list");
  190.       lb.MultiSelect(FALSE);
  191.       lb.Labels((List*)(~0L));
  192.       break;
  193.     case 5:
  194.       DemoWindow.Caption("No separators, no title, 1 column.");
  195.       lb.Labels(&labelList);
  196.       lb.ColumnInfo(fancy_ci);
  197.       lb.VertSeparators(FALSE);
  198.       lb.ColumnTitles(FALSE);
  199.       lb.AutoFit(TRUE);
  200.       break;
  201.     case 6:
  202.       DemoWindow.Caption("Fancy");
  203.       lb.Labels(&imageList);
  204.       lb.ColumnInfo(fancy_ci);
  205.       lb.AutoFit(TRUE);
  206.       break;
  207.     case 7:
  208.       DemoWindow.Caption("Read-only");
  209.       lb.Labels(&labelList);
  210.       lb.ColumnInfo(ci);
  211.       lb.AutoFit(TRUE);
  212.       lb.Selected(-1);
  213.       break;
  214.     case 8:
  215.       DemoWindow.Caption("Disabled");
  216.       lb.Disabled();
  217.       lb.ReadOnly();
  218.       break;
  219.     case 9:
  220.       DemoWindow.Caption("No scrollbars, borderless");
  221.       lb.Disabled(FALSE);
  222.       lb.HorizontalProp(FALSE);
  223.       lb.VerticalProp(FALSE);
  224.       lb.Borderless();
  225.       break;
  226.     default:
  227.       Application.Stop();
  228.     break;
  229.   }
  230. }
  231.  
  232. // Function to make a List of ListBrowserNodes from a couple of arrays.
  233. // Just to demonstrate things, we make make three columns, 2 with text
  234. // (the same text) and the third with numbers.
  235. //
  236. BOOL makeLabelList(struct List *list, char** labels1, LONG* labels2)
  237. {
  238.   struct Node *node;
  239.   WORD i = 0;
  240.  
  241.   NewList(list);
  242.  
  243.   while (*labels1)
  244.   {
  245.     if (node = AllocListBrowserNode(3,
  246.             LBNA_Column, 0,
  247.               LBNCA_CopyText, TRUE,
  248.               LBNCA_Text, *labels1,
  249.               LBNCA_MaxChars, 40,
  250.               LBNCA_Editable, TRUE,
  251.             LBNA_Column, 1,
  252.               LBNCA_CopyText, TRUE,
  253.               LBNCA_Text, *labels1,
  254.               LBNCA_MaxChars, 40,
  255.               LBNCA_Editable, TRUE,
  256.             LBNA_Column, 2,
  257.               LBNCA_Integer, &labels2[i],
  258.               LBNCA_Justification, LCJ_RIGHT,
  259.             TAG_DONE))
  260.     {
  261.       AddTail(list, node);
  262.     }
  263.     else
  264.       break;
  265.  
  266.     labels1++;
  267.     i++;
  268.   }
  269.   return(TRUE);
  270. }
  271.  
  272. // Function to make a List of ListBrowserNodes from tw images.
  273. //
  274. BOOL makeImageList(struct List* list, Image* im1,Image* im2)
  275. {
  276.   if( im1 && im2 )
  277.   {
  278.     struct Node *node;
  279.     WORD i = 0;
  280.  
  281.     NewList(list);
  282.  
  283.     if (node = AllocListBrowserNode(1,
  284.             LBNA_Column, 0,
  285.               LBNCA_Image, im1,
  286.               LBNCA_Justification, LCJ_CENTRE,
  287.             TAG_DONE))
  288.     {
  289.       AddTail(list, node);
  290.     }
  291.     else
  292.       return FALSE;
  293.  
  294.     if (node = AllocListBrowserNode(1,
  295.             LBNA_Column, 0,
  296.               LBNCA_Image, im2,
  297.               LBNCA_Justification, LCJ_CENTRE,
  298.             TAG_DONE))
  299.     {
  300.       AddTail(list, node);
  301.     }
  302.     else
  303.       return FALSE;
  304.  
  305.     return(TRUE);
  306.   }
  307.   return(FALSE);
  308. }
  309.  
  310. //
  311. // Function to free an Exec List of ListBrowser nodes.
  312. //
  313. VOID freeList(struct List *list)
  314. {
  315.   struct Node *node, *nextnode;
  316.  
  317.   node = list->lh_Head;
  318.   while (nextnode = node->ln_Succ)
  319.   {
  320.     FreeListBrowserNode(node);
  321.     node = nextnode;
  322.   }
  323.   NewList(list);
  324. }
  325.  
  326.